package com.archway.appframe.web.interceptor;



import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class DefaultSessionInterceptor implements HandlerInterceptor {

	@Override
	public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
		
		//这里可以做session超时覆盖
		//request.getSession().setMaxInactiveInterval(15);
		//request.getSession().setMaxInactiveInterval(60*30);
		
		//打印出session中有些什么
//		Enumeration e =request.getSession().getAttributeNames();
//		while (e.hasMoreElements()) {
//			Object object = (Object) e.nextElement();
//			System.out.println(object);
//		}
		//如果后来的服务中设置了UserInfoSession sesion，则二次访问时，session对象能获取到
//		SessionBean sessionBean =  (SessionBean) request.getSession().getAttribute("scopedTarget.sessionBean");
//		if(sessionBean!=null){
//			//System.out.println("sessionBean is not null !!!");
//		}else{
//			//System.out.println("sessionBean is null !!!");
//		}
		//这里可以设置安全属性 ，如过滤没有登录的访问，由于可以做成可配置的，就算后期有什么失误，这里也可以一并做设置，修改数据库配置，然后重启就好了
		//如果不安全可以返回false;
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest request,HttpServletResponse response, Object handler,ModelAndView modelAndView) throws Exception {

	}

	@Override
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex)
			throws Exception {

	}

}
